var JSONxEdit_jsonEditorForm = new Ext.FormPanel ({
	id: 'JSONxEdit_FormPanel_editorForm',
	title: 'Editor',
	frame: true,
	hideLabels: false,
	defaultType: 'textarea',
	height: 200,
	items: [
	new Ext.form.TextArea({
		name: 'key',
		id: 'JSONxEdit_FormPanel_editorForm_key',
		fieldLabel: "Key",
		anchor: '90%'
	}),
	new Ext.form.TextArea({
		name: 'value',
		id: 'JSONxEdit_FormPanel_editorForm_value',
		fieldLabel: "Value",
		anchor: '90%',
		listeners: {
			'change': function () {
				if ( Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").disabled )
					Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").setValue( Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").getValue() );
			}
		}
	}),
	new Ext.form.Checkbox({
		name: 'isNull',
		id: 'JSONxEdit_FormPanel_editorForm_isNull',
		fieldLabel: "isNull",
		listeners: {
			'check': function (checkbox, checked) {
				if (checked)
				{
					Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").setValue("null");
					Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").fireEvent("change");
					Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").disable();
				}
				else
				{
					Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").enable();
				}
			}
		}
	}),
	new Ext.form.TextField({
		name: 'key_id',
		id: 'JSONxEdit_FormPanel_editorForm_keyId',
		hidden: true,
		hideLabel: true
	})
	],
	buttons: [{
		text: 'SAVE',
		handler: saveChildToTree
	}],
	listeners: {
		'disable': function () {
			Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").setValue("");
			Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").setValue("");
			Ext.getCmp("JSONxEdit_FormPanel_editorForm_isNull").setValue(false);
			Ext.getCmp("JSONxEdit_FormPanel_editorForm_keyId").setValue("");
		},
		'enable': function () {
			if ( Ext.getCmp("JSONxEdit_FormPanel_editorForm_isNull").getValue() )
				Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").disable();
			else
				Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").enable();
		}
	}
});


var loginComboTpl = new Ext.XTemplate(
	'<tpl for="."><div class="x-combo-list-item">{field1}</div></tpl>'
	);


var JSONxEdit_jsonEditorObjectForm = new Ext.FormPanel ({
	id: 'JSONxEdit_FormPanel_editorObjectForm',
	title: 'Editor Array/Objekt',
	frame: true,
	hideLabels: false,
	defaultType: 'textarea',
	height: 200,
	items: [
	/*new Ext.form.ComboBox({
			name: 'json_index_type',
			id: 'JSONxEdit_FormPanel_editorObjectForm_index_type',
			fieldLabel: "Typ",
			store: [["Objekt","object"],["Array","array"]],
			typeAhead: true,
			forceSelection: true,
			tpl: loginComboTpl,
			triggerAction: 'all',
			value: "object",
			emptyText:'Standard ist "Objekt"',
			selectOnFocus:true,
			anchor: '90%',
			listeners: {
				'blur': function ( field ) {
					if ( field.getValue() == "" )
					{
						field.setValue("object");
					}
				}
			}
		}),*/
	new Ext.form.TextArea({
		name: 'json_index',
		id: 'JSONxEdit_FormPanel_editorObjectForm_index',
		fieldLabel: "Index",
		anchor: '90%'
	}),
	new Ext.form.TextField({
		name: 'index_id',
		id: 'JSONxEdit_FormPanel_editorObjectForm_indexId',
		hidden: true,
		hideLabel: true
	})
	],
	buttons: [{
		text: 'SAVE',
		handler: saveParentToTree
	}],
	listeners: {
		'disable': function () {
			Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_index").setValue("");
			Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_indexId").setValue("");
		}
	}
});

var JSONxEdit_jsonPartForm = new Ext.FormPanel ({
	id: 'JSONxEdit_FormPanel_partForm',
	title: 'JSON Part',
	frame: true,
	hideLabels: false,
	defaultType: 'textarea',
	height: 200,
	items: [
	new Ext.form.TextArea({
		name: 'json_part',
		id: 'JSONxEdit_FormPanel_partForm_jsonPart',
		fieldLabel: "JSON Part",
		anchor: '90%'
	})
	],
	buttons: [{
		text: 'SAVE',
		handler: saveJsonPartToTree
	}],
	listeners: {
		'disable': function () {
			Ext.getCmp("JSONxEdit_FormPanel_partForm_jsonPart").setValue("");
		}
	}
});


var JSONxEdit_jsonEditorTabPanel = new Ext.TabPanel({
	region: 'center',
	id: 'JSONxEdit_TabPanel_jsonEditor',
	title: 'Editor',
	frame: true,
	split: true,
	activeTab: 0,
	items:[
	JSONxEdit_jsonEditorForm,
	JSONxEdit_jsonEditorObjectForm,
	JSONxEdit_jsonPartForm
	],
	listeners: {
		'afterlayout': {
			fn: function(p){
				disableEditor();
			},
			single: true // important, as many layouts can occur
		}
	}
});